home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
vc
/
pro3
/
shel2dos.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-25
|
2KB
|
79 lines
===========================================================================
BBS: The Abacus * HST/DS * Potterville MI
Date: 05-23-93 (19:40) Number: 65
From: BOB STOUT Refer#: 176
To: DANIEL LYNES Recvd: NO
Subj: Shelling to OS Conf: (36) C Language
---------------------------------------------------------------------------
In a message of <May 22 00:58>, Daniel Lynes (1:229/516@fidonet) writes:
>/* Demonstrates use of the system() function */
>#include <stdlib.h>
>main() {
> char input[40];
> input = "command.com"; /* Or 4DOS.COM, if you're using 4DOS */
> system(input); /* This is the line right here */
>}
A more robust solution from SNIPPETS:
/*
** SHEL2DOS.C - Shell to DOS from a running program
**
** Original Copyright 1989-1991 by Bob Stout as part of
** the MicroFirm Function Library (MFL)
**
** This subset version is hereby donated to the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
int shell_to_DOS(void)
{
char *comspec, prompt[256], *oldprompt;
int retval;
comspec = getenv("COMSPEC");
if(comspec == NULL)
comspec = "COMMAND.COM"; /* Better than nothing... */
sprintf(prompt, "PROMPT=[Type EXIT to return to program]\r\n%s",
oldprompt = getenv("PROMPT"));
putenv(prompt);
retval = spawnlp(0, comspec, comspec, NULL);
sprintf(prompt, "PROMPT=%s", oldprompt);
putenv(prompt);
return retval;
}
#ifdef TEST
#include <stdio.h>
void main(void)
{
int retval = shell_to_DOS();
printf("shell_to_DOS() returned %d\n", retval);
retval = shell_to_DOS();
printf("shell_to_DOS() returned %d\n", retval);
}
#endif
--- QM v1.00
* Origin: MicroFirm : Down to the C in chips (1:106/2000.6)
SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20